package com.hspedu.homework;

import java.util.ArrayList;

/**
 * @Author Stringzhua
 * @Date 2024/3/13 18:58
 * description:
 */
@SuppressWarnings("all")
public class homework01 {
    public static void main(String[] args) {
        ArrayList arrayList = new ArrayList();
        arrayList.add(new News("新冠确诊病例超千万,数百万印度信徒赴恒河\"圣浴\"引民众担忧"));
        arrayList.add(new News("男子突然想起2个月前钓的鱼还在网兜里,捞起一看赶紧放生"));

        //要求倒叙遍历
        int size = arrayList.size();
        for (int i = size - 1; i >= 0; i--) {
//            System.out.println("arrayList = " + arrayList.get(i));
            News news = (News) arrayList.get(i);
            System.out.println(processTitle(news.getTitle()));
        }
    }

    //写一个方法处理显示新闻标题 process处理
    public static String processTitle(String title) {
        if (title == null) {
            return "";
        }
        if (title.length() > 15) {
            return title.substring(0, 15) + "......";//0<=title<15  [0,15)
        } else {
            return title;
        }
    }
}

class News {
    private String title;
    private String text;

    @Override
    public String toString() {
        return "News{" +
                "title='" + title + '\'' +
                '}';
    }

    public News(String title) {
        this.title = title;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getText() {
        return text;
    }

    public void setText(String text) {
        this.text = text;
    }
}
